Class TimingEngine
java.lang.Object
TimingEngine
public class TimingEngine
- extends java.lang.Object
The timer engine for a lap timer application. This engine can keep
track of a 'run'. A run is a sequence of one or more consecutive laps.
The timer records single lap times and the time for the total run,
and it calculate averages and speed.
- Version:
- 20 September 2004?, Bugs added September 18, 2012, Bugs Fixed May 11, 2016
- Author:
- Michael Kolling?, Lynn Marshall May 11, 2016, Aly Moursy May 11, 2016
|
Constructor Summary |
TimingEngine()
Create a TimingEngine object. |
|
Method Summary |
java.lang.String |
getAverageSpeed()
Return the average speed in this run in meters per second. |
java.lang.String |
getAverageTime()
Return the average time for a lap in this run. |
int |
getLapCount()
Return the number of laps completed in this run. |
int |
getLapLength()
|
java.lang.String |
getLastTime()
Return the time of the last lap completed. |
java.lang.String |
getStatus()
Return the current status of the timer. |
java.lang.String |
getTotalTime()
|
void |
setLapLength(int length)
Set the length of a lap. |
void |
startLap()
Instruct the timer to start timing a lap. |
void |
stop()
Stop timing. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TimingEngine
public TimingEngine()
- Create a TimingEngine object. The object will be initialised at 0,
status is "Stopped", ready to start timing. The default lap length
is 400 m.
getAverageSpeed
public java.lang.String getAverageSpeed()
- Return the average speed in this run in meters per second.
The result is a string such as "73 m/s".
- Returns:
- Average speed in this run in meters per second.
getAverageTime
public java.lang.String getAverageTime()
- Return the average time for a lap in this run.
The result is a string in the format "m:ss:hh".
- Returns:
- average time for a lap in this run.
getLapCount
public int getLapCount()
- Return the number of laps completed in this run.
- Returns:
- number of laps
getLapLength
public int getLapLength()
- Returns:
- Return the length of a lap.
getLastTime
public java.lang.String getLastTime()
- Return the time of the last lap completed.
The result is a string in the format "m:ss:hh", where m is
the number of minutes, ss the number of seconds, and hh the number
of hundredths of a second. For example "7:02:43".
- Returns:
- Time taken to complete last lap
getStatus
public java.lang.String getStatus()
- Return the current status of the timer. The status is one of the
two Strings "Timing..." or "Stopped", indicating whether this
timer is currently running or stopped.
- Returns:
- Timing if running else return Stopped
getTotalTime
public java.lang.String getTotalTime()
- Returns:
- the total time of the last or current run.
The result is a string in the format "m:ss:hh".
setLapLength
public void setLapLength(int length)
- Set the length of a lap.
- Parameters:
length - the length of the lap
startLap
public void startLap()
- Instruct the timer to start timing a lap.
If we were not timing before, this starts the timer for a new
run. If we were already timing, this starts a new lap, adding the
current lap time to the total.
stop
public void stop()
- Stop timing. Add the current lap time to the total, and set
the timer into idle mode (waiting for a new run).